<clickhouse>
  <profiles>
    <!-- 记录读取日志 -->
    <log_queries>1</log_queries>
    <default>
      <!-- 最大使用内存,设置总体内存的50%，单位字节-->
      <max_memory_usage>{{ max_memory_usage }}</max_memory_usage>
      <!-- 用户查询最大使用内存，即除系统内部执行的sql外 -->
      <max_memory_usage_for_user>{{ max_memory_usage_for_user }}</max_memory_usage_for_user>
      <!-- 整个ck服务最大使用内存,24GB-->
      <max_memory_usage_for_all_queries>25769803776</max_memory_usage_for_all_queries>
      <!-- 使用压缩缓存 -->
      <use_uncompressed_cache>0</use_uncompressed_cache>
      <!-- 最大线程数，可适当根据服务器性能调节 -->
      <max_threads>{{ ansible_processor_vcpus * 2 }}</max_threads>
      <max_bytes_before_external_sort>0</max_bytes_before_external_sort>
      <!-- 线程池大小，太小会影响查询性能 -->
      <background_pool_size>8</background_pool_size>
      <!-- join查询时发生异常会终止，尽量避免join查询！ -->
      <joined_subquery_requires_alias>0</joined_subquery_requires_alias>
      <!-- 遇到错误是否直接停止，生产环境强烈推荐配置，否则可能引发CPU打满等问题 -->
      <join_overflow_mode>break</join_overflow_mode>
      <!-- 最大group行数 -->
      <max_rows_to_group_by>10000000000</max_rows_to_group_by>
      <!-- 最大查询数 -->
      <max_query_size>5242880</max_query_size>
      <!-- 可提高group的查询速率 -->
      <group_by_overflow_mode>any</group_by_overflow_mode>
      <!-- 查询结果超过内存限制时抛出异常 -->
      <result_overflow_mode>throw</result_overflow_mode>
      <!-- 发生其他超过内存限制时终止操作 -->
      <distinct_overflow_mode>break</distinct_overflow_mode>
      <!-- 最大group字节数 -->
      <max_bytes_before_external_group_by>50000000000</max_bytes_before_external_group_by>
      <!-- 插入线程数 -->
      <max_insert_threads>{{ ansible_processor_vcpus }}</max_insert_threads>
      <load_balancing>random</load_balancing>
      <distributed_product_mode>global</distributed_product_mode>
    </default>

    <!-- 配置文件只读 -->
    <readonly>
      <readonly>1</readonly>
    </readonly>

  </profiles>

  <!-- Users and ACL. -->
  <users>
    <!-- If user name was not specified, 'default' user is used. -->
    <default>
      <password>{{ ck_default_password }}</password>
      <!-- 允许外部登录 -->
      <networks incl="networks" replace="replace">
        <ip>::/0</ip>
      </networks>

      <!-- Settings profile for user. -->
      <profile>default</profile>
      <!-- Quota for user. -->
      <quota>default</quota>
      <!-- User can create other users and grant rights to them. -->
      <access_management>1</access_management>
      <!-- User can manipulate named collections. -->
      <named_collection_control>1</named_collection_control>
    </default>
  </users>

  <!-- Quotas. -->
  <quotas>
    <!-- Name of quota. -->
    <default>
      <!-- Limits for time interval. You could specify many intervals with different limits. -->
      <interval>
        <!-- Length of interval. -->
        <duration>3600</duration>
        <!-- No limits. Just calculate resource usage for time interval. -->
        <queries>0</queries>
                <errors>0</errors>
                <result_rows>0</result_rows>
                <read_rows>0</read_rows>
                <execution_time>0</execution_time>
            </interval>
        </default>
    </quotas>
</clickhouse>
